import time

from functools import wraps


def repeat_execution(
    times: int = 1,
    delay: int = 0,
):
    """ 三层装饰器：重复执行函数 """

    def decorator(func):

        @wraps(func)
        def wrapper(*args, **kwargs):
            results = []

            for i in range(times):
                print(f"执行 #{i + 1}/{times}")
                result = func(*args, **kwargs)
                results.append(result)

                if (
                    delay > 0
                    and i < times - 1
                ):
                    print(f"等待 {delay} 秒...")
                    time.sleep(delay)

            return results

        return wrapper

    return decorator


@repeat_execution(times=3, delay=1)
def calculate_sum(a, b):
    print(f"计算 {a} + {b}")
    return a + b


# 测试
print("\n测试三层装饰器:")
results1 = calculate_sum(5, 3)
print("所有结果:", results1)
